/*
 Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai).
 n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0).
 Find two lines, which together with x-axis forms a container, such that the container contains the most water.

 Note: You may not slant the container and n is at least 2.
 */
/**
 * 给定一组非负整数，[a1,a2,a3,...,an]，每个数在坐标轴上画两个点(i,ai)和(i,0)，并连线，即垂直于x轴的一条直线。
 * 那现在有n个数，即有n条直线。把直线视为一块挡板，现在要找到两块挡板之间盛水最多的，返回盛水量。
 */

/**
 * @param {number[]} height
 * @return {number}
 */
var maxArea = function(height) {
    //找到两块挡板间，容积最大的。
    let max = 0;
    let left = 0;
    let right = height.length - 1;
    while (left < right) {
        max = Math.max(max, Math.min(height[left], height[right]) * (right - left));
        if (height[left] < height[right])
            left++;
        else
            right--;
    }
    return max;
};

console.log(maxArea([1,3,3,9,4]));//9
console.log(maxArea([1,3,3,9,4,0,0,0,0,0,0,0,1]));//12